﻿using GN.Pay.TradeChannel.DefaultImpl;
using GN.Pay.Utils;
using GN.Pay.Utils.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.WeiXin.Response
{
    /// <summary>
    /// Js Api 支付响应
    /// </summary>
    [Serializable]
    class JsApiPayResponse : PayResponse
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xml"></param>
        public JsApiPayResponse(string xml)
            : base(xml)
        {
        }
       

        /// <summary>
        /// 转为结果
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public override ITradePayApplyResult ToResult(WeiXinConfigure config)
        {
            ToResultCheck(config);
            SignDictionary sign = new SignDictionary();
            sign["appId"] = this.AppId; 
            sign["package"] = "prepay_id=" + this.Prepay_Id;
            sign["nonceStr"] = Guid.NewGuid().ToString("N");
            sign["timeStamp"] = DateTimeUtils.CurrentTimeStampSeconds.ToString();
            sign["signType"] = "MD5";
            string content = sign.UrlLinkString() + "&key=" + config.ConfigureInfo.Key;
            sign["paySign"] = Md5Utils.Sign(content, config.Encoding).ToUpperInvariant();
            return new TradePayApplyResult(Prepay_Id, "", sign.ToJson(true), TradePayApplyResultCallType.App_Json);
        }
    }
}
